﻿using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbFavoriteRequestTest and is intended
    ///     to contain all TmdbFavoriteRequestTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbFavoriteRequestTest
    {
        /// <summary>
        ///     A test for TmdbFavoriteRequest Constructor
        /// </summary>
        [TestMethod]
        public void TmdbFavoriteRequestConstructorTest()
        {
            var target = new TmdbFavoriteRequest();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for AddToFavorite
        /// </summary>
        [TestMethod]
        public void AddToFavoriteTest()
        {
            var target = new TmdbFavoriteRequest();
            bool expected = new Random().Next( 0, Int32.MaxValue ) % 2 == 0;
            target.AddToFavorite = expected;
            bool actual = target.AddToFavorite;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbFavoriteRequest();
            int expected = new Random().Next( 0, Int32.MaxValue );
            target.Id = expected;
            int actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbFavoriteRequest()
                {
                    Id = new Random().Next( 0, Int32.MaxValue ),
                    AddToFavorite = new Random().Next( 0, Int32.MaxValue ) % 2 == 0
                };
            var json = await target.Serialize();
            Assert.AreEqual(String.Format("{0}\"movie_id\":{1},\"favorite\":{2}{3}", "{", target.Id, target.AddToFavorite.ToString().ToLower(), "}"), json);
            var actual = await target.DeserializeJson<TmdbFavoriteRequest>( json );

            Assert.AreEqual( target.Id, actual.Id );
            Assert.AreEqual(target.AddToFavorite, actual.AddToFavorite);
        }
    }
}